package LesThreads;

public class Nombres {
	private int n = 1, carre;
	private boolean pret = false;

	public synchronized void calcul() throws InterruptedException {

		if (!pret) {
			n++;
			carre = n * n;
			notifyAll();
		} else
			wait();
	}

	public synchronized void affiche() {
		try {
			if (pret) {
				System.out.println(n + " a pour carre " + carre);
				notifyAll();
				pret = false;
			} else
				wait();
		} catch (InterruptedException e) {
			// TODO: handle exception
		}
	}
	public boolean pret(){
		return pret;
	}
}
